package LeetCode;

public class LC_671_SecondMinimumNodeInaBinaryTree {

    public static void main(String[] args) {

    }

    class Solution {
        int findSecondMinimumValue(TreeNode root) {
            if (root == null) return -1;
            if (root.left == null && root.right == null) return -1;
            assert root.left != null;
            int left = root.left.val;
            int right = root.right.val;
            if (root.left.val == root.val) left = findSecondMinimumValue(root.left);
            if (root.right.val == root.val) right = findSecondMinimumValue(root.right);
            if (left != -1 && right != -1) return Math.min(left, right);
            else if (left != -1) return left;
            else return right;
        }
    }

}